package com.ruibang.glass.produce.controller.system;

import com.ruibang.glass.common.constants.RedisKey;
import com.ruibang.glass.produce.domain.req.ProductLineReq;
import com.ruibang.glass.produce.domain.req.WorkshopReq;
import com.ruibang.glass.produce.entity.ProductLine;
import com.ruibang.glass.produce.entity.Workshop;
import com.ruibang.glass.produce.service.ProductLineService;
import com.ruibang.glass.produce.service.WorkshopService;
//import com.teaming.cloud.framework2.autoconfigure.redis.RedisService;
import com.teaming.cloud.framework2.autoconfigure.redis.RedisSingleService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDateTime;

/**
 * @Author: songJinKang
 * @CreateTime: 2023-11-15  19:09
 * @Description: TODO:产线控制器
 * @Version: 1.0
 */

@Api(tags = "产线控制器")
@RestController
@RequestMapping("/api/glass/produce/productLine")
public class ProductLineController {

    @Autowired
    private ProductLineService productLineService;

//    @Autowired
//    private RedisService redisService;

    @Autowired
    private RedisSingleService redisService;

    @GetMapping("/getProductLineList")
    @ApiOperation(value = "获取产线列表", response = ResultBody.class)
    public ResultBody getProductLineList(String workshopId) {
        return ResultBody.success(productLineService.getProductLineList(workshopId));
    }

    @PostMapping("/queryProductLine")
    @ApiOperation(value = "查询产线", response = ResultBody.class)
    public ResultBody queryProductLine(@RequestBody ProductLineReq productLineReq) {
        return ResultBody.success(productLineService.queryProductLine(productLineReq));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增", response = ResultBody.class)
    public ResultBody add(@RequestBody @Valid ProductLine productLine) {
        redisService.hset(RedisKey.PRODUCT_LINE_GROUP_TYPE, productLine.getProductLineId(), productLine.getProductLineName());
        productLineService.save(productLine);
        return ResultBody.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除", response = ResultBody.class)
    public ResultBody deleteById(@PathVariable String id) {
        productLineService.removeById(id);
        return ResultBody.success();
    }

    @PutMapping("/edit")
    @ApiOperation(value = "修改", response = ResultBody.class)
    public ResultBody edit(@RequestBody @Valid ProductLine productLine) {
        productLineService.updateById(productLine);
        redisService.hset(RedisKey.PRODUCT_LINE_GROUP_TYPE, productLine.getProductLineId(), productLine.getProductLineName());
        return ResultBody.success();
    }
}
